<input type="hidden" name='url' id='url' value="<?php echo $this->Html->url( null, true ); ?>">
<div class="row">
 	<div class="col-md-12">
		<div class="page-header">
		  <h1>Sucursales</h1>
		</div>
		<div class="btn-group pull-left">
			<?php echo $this->Html->link(__('Nuevo', true), array('controller' => 'branches', 'action' => 'add','admin'=>true ),array('class'=>'btn btn-default')); ?> 				  
		    <a href="#" class="btn btn-default" id='edit_bt'>Editar</a>
		    <button id='delete_bt'class="btn btn-default">Eliminar</button>
		    <button id='history_bt'class="btn btn-default">Historial</button>
		    <button type="button" class="btn btn-default ">Email</button>
		</div>
		<br>
		<br>
		<table class="table table-hover table-striped table-bordered">
				<thead>
					<tr>
						<th>#</th>
						<th> <?php echo $this->Paginator->sort('name', 'Sucursal'); ?></th>
						<th><?php echo $this->Paginator->sort('address', 'Domicilio'); ?></th>
						<th><?php echo $this->Paginator->sort('phone', 'Teléfono'); ?></th>
						<!-- <th>Action</th> -->
					</tr>
				</thead>
				<tbody>
					<?php foreach ($data as $item) :?>
						<tr>
							<td><input type="checkbox" name='branch_ids[]' value="<?php echo $item['Branches']['id']?>"></td>
							<td><a class='clients' href="#" data-id="<?php echo $item['Branches']['id']?>">
								<?php echo $item['Branches']['name']?></a>
							</td>
							<td><?php echo $item['Branches']['address']?></td>
							<td><?php echo $item['Branches']['phone']?></td>				
						</tr>
					<?php endforeach;?>	
				</tbody>
			</table>
			  <ul class="pagination">
				<li><?php echo $this->Paginator->first('<i class="glyphicon glyphicon-step-backward"></i>&nbsp;', array('class'=>'disabled', 'escape'=>false)); ?></li>
				<li><?php echo $this->Paginator->prev('<i class="glyphicon glyphicon-backward"></i>&nbsp;', array('escape'=>false)) ;?></li>
				<li><?php echo $this->Paginator->numbers(array('separator'=>'')); ;?> </li>
				<li><?php echo $this->Paginator->next('<i class="glyphicon glyphicon-forward"></i>&nbsp;', array('escape'=>false)) ;?></li><li><?php echo $this->Paginator->last('<i class="glyphicon glyphicon-step-forward"></i>&nbsp;', array('class'=>'disabled','escape'=>false)); ?></li>				
			</ul>			
 	</div>
</div>

<div class="modal bs-example-modal-lg " id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Datos Clientes</h4>
      </div>
      <div class="modal-body">
      	<div class="row">
      		<div class="col-md-12 well ">
	      		<div class="form-group">
				    <label for="inputEmail3" class="col-sm-4 control-label">Nombre y Apellido</label>
				    <div class="col-sm-6">					     
				    	<p id='name'></p>  
				    </div>
			  	</div>
			  	<div class="clearfix"><br><br></div>
			  	<div class="form-group">
				    <label for="inputEmail3" class="col-sm-4	 control-label">DNI</label>
				    <div class="col-sm-6">
				      	<p id='dni'></p>
				    </div>
			  	</div>
			  	<div class="clearfix"><br><br></div>
			  	<div class="form-group">
				    <label for="inputEmail3" class="col-sm-4 control-label">Email</label>
				    <div class="col-sm-6">					     
				      	<p id='email_p'></p>
				    </div>
			  	</div>
			  	<div class="clearfix"><br><br></div>
			  		<div class="form-group">
					    <label for="inputEmail3" class="col-sm-4 control-label">Domicílio</label>
					    <div class="col-sm-6">					     
					      	<p id='address'> </p>
					    </div>
				  	</div>
			  	<div class="clearfix"><br><br></div>
			  		<div class="form-group">
					    <label for="inputEmail3" class="col-sm-4 control-label">Teléfono</label>
					    <div class="col-sm-6">					     
					      	<p id='phone_home'></p>
					    </div>
				  	</div>
			  	<div class="clearfix"><br><br></div>
			  		<div class="form-group">
					    <label for="inputEmail3" class="col-sm-4 control-label">Celular</label>
					    <div class="col-sm-6">					     
					      	<p id='phone_cell'></p>
					    </div>
				  	</div>
			  	<div class="clearfix"><br><br></div>
			  		<div class="form-group">
				    	<label for="inputEmail3" class="col-sm-4 control-label">Fecha de Nacimiento</label>
					    <div class="col-sm-6">					     
					      	<p id='birthday'></p>
					    </div>
				  	</div>	
			  	<div class="clearfix"><br><br></div>
			  		<div class="form-group">
					    <label for="inputEmail3" class="col-sm-4 control-label">Observacíon</label>
					    <div class="col-sm-6">					     
					      	<p id='observation'> Peter John</p>
					    </div>
				  	</div>
			  	<div class="clearfix"><br><br></div>
			  	

		  	</div>

				  	<!--
      		<div class="col-md-12 well ">
      			<div class="col-sm-7">
      				<div class="form-group">
					    <label for="inputEmail3" class="col-sm-5 control-label">Nombre y Apellido</label>
					    <div class="col-sm-3">					     
					    <p id='name'></p>  
					    </div>
				  	</div>
      			</div>
      			<div class="col-sm-5">
      				<div class="form-group">
					    <label for="inputEmail3" class="col-sm-2	 control-label">DNI</label>
					    <div class="col-sm-6">					     
					      
					      <p id='dni'></p>
					    </div>
				  	</div>
      			</div>
      		</div>
      		<div class="col-md-12 well ">
      			<div class="col-sm-6">
      				<div class="form-group">
					    <label for="inputEmail3" class="col-sm-3 control-label">Email</label>
					    <div class="col-sm-5">					     
					      <p id='email_p'></p>
					    </div>
				  	</div>
      			</div>
      			<div class="col-sm-6">
      				<div class="form-group">
					    <label for="inputEmail3" class="col-sm-3 control-label">Domicílio</label>
					    <div class="col-sm-5">					     
					      <p id='address'> </p>
					    </div>
				  	</div>
      			</div>
      		</div>
      		<div class="col-md-12 well ">
      			<div class="col-sm-6">
      				<div class="form-group">
					    <label for="inputEmail3" class="col-sm-3 control-label">Teléfono</label>
					    <div class="col-sm-5">					     
					      <p id='phone_home'></p>
					    </div>
				  	</div>
      			</div>
      			<div class="col-sm-6">
      				<div class="form-group">
					    <label for="inputEmail3" class="col-sm-3 control-label">Celular</label>
					    <div class="col-sm-5">					     
					      <p id='phone_cell'></p>
					    </div>
				  	</div>
      			</div>
      		</div>
      		<div class="col-md-12 well ">
      			<div class="form-group">
				    <label for="inputEmail3" class="col-sm-3 control-label">Fecha de Nacimiento</label>
				    <div class="col-sm-5">					     
				      <p id='birthday'> Peter John</p>
				    </div>
			  	</div>	
      		</div>
      		<div class="col-md-12 well ">
      			
  				<div class="form-group">
				    <label for="inputEmail3" class="col-sm-3 control-label">Observacíon</label>
				    <div class="col-sm-5">					     
				      <p id='observation'> Peter John</p>
				    </div>
			  	</div>
      			
      		</div>
      		 -->
      	</div> 
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
        <!-- <button type="button" class="btn btn-primary">Save changes</button> -->
      </div>
    </div>
  </div>
</div>


<script type="text/javascript">
/*
	function get_check_id(){
	    var result=0;
	    $('input[name=client_ids\\[\\]]').each(function() {
	        if( $(this).is(":checked")){
	            var user_id = $(this).val();	           
	            result =  user_id;
	        }
	    });
	    return result;
	}


	$(function(){
		
		var url=$("#url").val();
		$("#edit_bt").click(function(){
			chck_id= get_check_id();
			redirect_url=url+"/edit/"+chck_id
			window.location.replace(redirect_url);
			return false;
		});

		$("#edit_bt").click(function(){
			chck_id= get_check_id();
			redirect_url=url+"/edit/"+chck_id
			window.location.replace(redirect_url);
			return false;
		});

		$("#delete_bt").click(function(){
			chck_id= get_check_id();			
			var selected = new Array();
			$("input:checkbox:checked").each(function() {
				selected.push($(this).val());
			});
			var client_json = $.post(url+"/delete",{ids:selected},function(result){
				location.reload();
				//return false;
		  	});			
			return false;
		});


	$(".clients").click(function(){
		var data = $(this).data();
		var client_json = $.getJSON("clients/get_data/"+data.id+"",function(result){
			 console.debug(" ==> result: %o",result);
			 $("#dni").text(result.dni);
			 $("#name").text(result.first_name+' '+result.last_name);
			 $("#email_p").text(result.email);
			 $("#address").text(result.address);
			 $("#phone_home").text(result.phone_home);
			 $("#phone_cell").text(result.phone_cell);
			 $("#birthday").text(result.birthday);
			 $("#observation").text(result.observation);
			$("#myModal").modal("show");
		return result;
	  	});
		
	});
});*/
</script>
